package org.simple.framework.html.parser.process;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;

/**
 * 项目名称：fs-learn-video
 * 类名称：PreProcesser
 * 类描述：PreProcesser
 * 创建时间：2021/7/19
 *
 * @author sisyphus   (E-mail:1620657419@qq.com)
 * @version v1.0
 */
public class PreProcesser {

    Map<String, Function<String, Object>> functionMap = new HashMap<>();

    public void register(String name, Function<String, Object> function) {
        functionMap.put(name, function);
    }

    public Object process(String name, String string) {
        if (name == null || name.isEmpty()) {
            return string;
        }
        Function<String, Object> function = functionMap.get(name);
        if (function == null) {
            return string;
        }
        return function.apply(string);
    }

}
